package 并发编程18.HelloWorld里面有多少线程;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * @author idea
 * @data 2019/2/24
 */
public class Demo {

    public static void main(String[] args) {

        System.out.println("HelloWorld");
        ThreadMXBean threadMXBean=ManagementFactory.getThreadMXBean();
        long[] threadIds=threadMXBean.getAllThreadIds();
        ThreadInfo[] threadInfos=threadMXBean.getThreadInfo(threadIds);
        for (ThreadInfo threadInfo : threadInfos) {
            System.out.println(threadInfo.getThreadId()+":"+threadInfo.getThreadName());
        }
    }
}
